package com.boot.unity.api.wx.controller;

import com.alibaba.fastjson.JSONObject;
import com.boot.unity.api.wx.service.WxDeptsService;
import com.github.pagehelper.PageInfo;
import com.sun.istack.internal.NotNull;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 机构服务
 * type：2为车管所  type：3为驾校
 */
@RestController
@RequestMapping("/wx/depts")
@Validated
public class WxDeptsController {
    private final Log logger = LogFactory.getLog(WxDeptsController.class);


    private final static ArrayBlockingQueue<Runnable> WORK_QUEUE = new ArrayBlockingQueue<>(9);

    private final static RejectedExecutionHandler HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();

    @Autowired
    private WxDeptsService wxDeptsService;

//    @Autowired
//    private WxDeptsService wxDeptsService;

    /**
     * 获取驾校列表
     * <p>
     *
     * @param sort  排序方式，支持"add_time", "retail_price"或"name"
     * @param order 排序类型，顺序或者降序
     * @return 驾校信息
     * @Param regionId    区域id
     * @Param starRating    星级
     */
    @GetMapping("list")
    public Object list(Integer regionId, Integer starRating, Integer type, String sort, String order) {
        if (sort == null){
            sort = "add_time";
        }
        if (type == null){
            type = 3;
        }
        if (order == null){
            order = "desc";
        }
        Integer page = 1;
        Integer limit = 30;
        JSONObject resurt = wxDeptsService.list( regionId, starRating, type, sort, order, page, limit);
        return resurt;

    }

    @GetMapping("detailormodel")
    public Object detailormodel(@NotNull Integer id, String model) {
        return wxDeptsService.detailormodel(id, model);
    }

    /**
     * * 获取教练车的车牌等信息
     * **/
    @GetMapping("getlicensePlate")
    public Object getlicensePlate(String schoolId,Integer page, Integer limit){
     return wxDeptsService.getlicensePlate(schoolId,page,limit);
    }

        //list_jbx
    @GetMapping("list_jbx")
    public Object list_jbx(Integer regionId, Integer starRating, Integer type, Integer page, Integer limit, String sort, String order) {
        if (sort == null){
            sort = "add_time";
        }
        if (type == null){
            type = 3;
        }
        if (order == null){
            order = "desc";
        }
       return wxDeptsService.list_jbx(regionId,starRating,type,page,limit,sort,order);

    }



    @GetMapping("xykhpm")
    public Object getXykx(){
        return wxDeptsService.getXykx();
    }

    @GetMapping("listCgJt")
    public Object listCgJt(Integer regionId, Integer starRating, Integer pid, Integer type, Integer page, Integer limit, String sort, String order) {
        if (sort == null){
            sort = "add_time";
        }
        if (type == null){
            type = 3;
        }
        if (order == null){
            order = "desc";
        }
        if (page == null){
            page = 1;
        }
        if (limit == null){
            limit = 30;
        }
        return wxDeptsService.listCgJt(regionId,starRating,pid,type,page,limit,sort,order);
    }


    /**
     * 星级驾校
     */
    @GetMapping("schoolStar")
    public Object schoolStar(){
        return wxDeptsService.setSchoolStar();
    }

    @GetMapping("mySchoolDetail")
    public Object mySchoolDetail(String id) {
        return wxDeptsService.mySchoolDetail(id);

    }

    /**
     * 当前用户的驾校信息
     * @param
     * @return
     */
    @GetMapping("mySchoolInfo")
    public Object mySchoolInfo(String uid,String key) {
        return wxDeptsService.mySchoolInfo(uid,key);
    }


    /**
     * 获取驾校列表
     * <p>
     *
     * @param page  分页页数
     * @param limit 分页大小
     * @param sort  排序方式，支持"add_time", "retail_price"或"name"
     * @param order 排序类型，顺序或者降序
     * @return 驾校信息
     * @Param regionId    区域id
     * @Param starRating    星级
     */
    @GetMapping("listByModel")
    public Object listByModel(String model, Integer regionId, Integer starRating, Integer type, Integer page, Integer limit, String sort, String order) {
        if (sort == null){
            sort = "add_time";
        }
        if (type == null){
            type = 0;
        }
        if (order == null){
            order = "desc";
        }
        if (page == null){
            page = 1;
        }
        System.out.println("考试驾驶类型：：：：："+model);
        limit = 1000;
        return wxDeptsService.listByModel(model, regionId, starRating, type, page, limit, sort,order);
    }



    /**
     * 机构详情
     *
     * @param id 机构ID
     * @return 机构详情
     */
    @GetMapping("detail")
    public Object detail(Integer id,String model) {
       return wxDeptsService.detail(id,model);
    }


    /**
     * 根据ID，获取驾校信息
     */
    @GetMapping("querySchoolDetail")
    public Object querySchoolDetail(Integer id){
        return wxDeptsService.querySchoolDetail(id);
    }

    /**
     * 获取当前教练认证状态

     * @return
     */
    @PostMapping("getCoachSign")
    @GetMapping("getCoachSign")
    public Object getCoachSign(String uid,String key) {
        return wxDeptsService.getCoachSign(uid,key);
    }

}
